/**
 * 初始化详情对话框
 */
var DhcNlpSchemaInfoDlg = {
    DhcNlpSchemaInfoData : {},
    validateFields: {
        keyDesc: {
            validators: {
                notEmpty: {
                    message: '描述不能为空'
                }
            }
        },
    	keyCode: {
            validators: {
                notEmpty: {
                    message: '代码不能为空'
                }
            }
        }
    }
};

/**
 * 清除数据
 */
DhcNlpSchemaInfoDlg.clearData = function() {
    this.DhcNlpSchemaInfoData = {};
}

/**
 * 设置对话框中的数据
 *
 * @param key 数据的名称
 * @param val 数据的具体值
 */
DhcNlpSchemaInfoDlg.set = function(key, val) {
    this.DhcNlpSchemaInfoData[key] = (typeof val == "undefined") ? $("[id=" + key+"]").val() : val;
    return this;
}

/**
 * 设置对话框中的数据
 *
 * @param key 数据的名称
 * @param val 数据的具体值
 */
DhcNlpSchemaInfoDlg.get = function(key) {
    return $("[name=" + key+"]").val();
}

/**
 * 关闭此对话框
 */
DhcNlpSchemaInfoDlg.close = function() {
    parent.layer.close(parent.layer.getFrameIndex(window.name)); //先得到当前iframe层的索引,再执行关闭   
}

/**
 * 收集数据
 */
DhcNlpSchemaInfoDlg.collectData = function() {
    this.set('id');
    this.set('parentId');
	this.set('keyCode');
	this.set('keyDesc');
	this.set('isActive', $('input[name="isActive"]').radio('getValue')?1:0);
};

/**
 * 验证数据是否为空
 */
DhcNlpSchemaInfoDlg.validate = function () {
    $('#DhcNlpSchemaInfoForm').data("bootstrapValidator").resetForm();
    $('#DhcNlpSchemaInfoForm').bootstrapValidator('validate');
    return $("#DhcNlpSchemaInfoForm").data('bootstrapValidator').isValid();
};

/**
 * 提交添加
 */
DhcNlpSchemaInfoDlg.addSubmit = function() {

    this.clearData();
    this.collectData();
    
    if (!this.validate()) {
        return;
    }

    //提交信息
    var ajax = new $ax(Sys.backendPath + "/cdc/nlpschemadic/add", function(data){
        Sys.success("添加成功!");
        window.parent.Dhcnlpschema.table.refresh();
        window.parent.SchemaDic.refreshParentNode();
        DhcNlpSchemaInfoDlg.close();
    },function(data){
        Sys.error("添加失败!" + data.responseJSON.message + "!");
    });
    ajax.set(this.DhcNlpSchemaInfoData);
    ajax.start();
}

/**
 * 提交修改
 */
DhcNlpSchemaInfoDlg.editSubmit = function() {

    this.clearData();
    this.collectData();
    if (!this.validate()) {
        return;
    }

    //提交信息
    var ajax = new $ax(Sys.backendPath + "/cdc/nlpschemadic/update", function(data){
        Sys.success("修改成功!");
        window.parent.Dhcnlpschema.table.refresh();
        window.parent.SchemaDic.refreshParentNode();
        DhcNlpSchemaInfoDlg.close();
    },function(data){
        Sys.error("修改失败!" + data.responseJSON.message + "!");
    });
    ajax.set(this.DhcNlpSchemaInfoData);
    ajax.start();
}

$(function() {
    Sys.initValidator("DhcNlpSchemaInfoForm", DhcNlpSchemaInfoDlg.validateFields);
});
